<?php

/**
* Reporter for SimpleTest
* simply stores information, do not print anything
*/

class WakTestReporter extends SimpleReporter {

    /**
    * @var current method
    */
    public $method='';

    /**
    * @var array messages source => message
    */
    var $messages=array();

    /**
    * @var bool tests result, true if no fail
    */
    var $status=true;

    /**
     *    Accessor for current status. Will be false
     *    if there have been any failures or exceptions.
     *    Used for command line tools.
     *    @return boolean        True if no failures.
     *    @access public
     */
    function getStatus() {
        if ($this->_exceptions + $this->_fails > 0) {
            return false;
        }
        return true;
    }

    /**
     *    Increments the pass count.
     *    @param string $message        Message is ignored.
     *    @access public
     */
    function paintPass($message) {
        $this->_passes++;
        $this->paintMessage($message,'pass');
        //$this->passCount=$this->_passes;
    }

    /**
     *    Increments the fail count.
     *    @param string $message        Message is ignored.
     *    @access public
     */
    function paintFail($message) {
        $this->_fails++;
        $this->paintMessage($message,'fail');
        $this->status=false;
    }

    /**
     *    Deals with PHP 4 throwing an error.
     *    @param string $message    Text of error formatted by
     *                              the test case.
     *    @access public
     */
    function paintError($message) {
        $this->paintException($message);
        $this->paintMessage($message,'error');
    }

    /**
     *    Deals with PHP 5 throwing an exception
     *    This isn't really implemented yet.
     *    @param Exception $exception     Object thrown.
     *    @access public
     */
    function paintException($exception) {
        $this->_exceptions++;
    }

    /**
     *    Accessor for the number of passes so far.
     *    @return integer       Number of passes.
     *    @access public
     */
    function getPassCount() {
        return $this->_passes;
    }

    /**
     *    Accessor for the number of fails so far.
     *    @return integer       Number of fails.
     *    @access public
     */
    function getFailCount() {
        return $this->_fails;
    }

    /**
     *    Accessor for the number of untrapped errors
     *    so far.
     *    @return integer       Number of exceptions.
     *    @access public
     */
    function getExceptionCount() {
        return $this->_exceptions;
    }

    /**
     *    Paints a simple supplementary message.
     *    @param string $message        Text to display.
     *    @access public
     */
    function paintMessage($message,$type='message') {
        $test=$this->getTestList();
        $class=isset($test[1])?$test[1]:'unknown class';
        $method=isset($test[2])?$test[2]:'unknown method';
        //$key='('.$n.') '.$test[1].'::'.$test[2];
        $this->messages[]=new WakTestMessage($message,$type,$class,$method);
    }

    /**
     *    Paints a formatted ASCII message such as a
     *    variable dump.
     *    @param string $message        Text to display.
     *    @access public
     */
    function paintFormattedMessage($message) {
        $this->paintMessage('<pre>'.$message.'</pre>');
    }

    /**
     *    By default just ignores user generated events.
     *    @param string $type        Event type as text.
     *    @param mixed $payload      Message or object.
     *    @access public
     */
    function paintSignal($type, &$payload) {
    }
}

class WakTestMessage {
    public function __construct($text,$type='message',$class='',$method=null) {
        $this->text=$text;
        $this->type=$type;
        $this->class=$class;
        $this->method=$method;
    }

    public function __toString() {
        return $this->text;
    }

    public $text;
    /**
     * @var string fail pass message error
     */
    public $type;

    public $class;

    public $method;
}
